home *** CD-ROM | disk | FTP | other *** search
/ Aminet 2 / Aminet AMIGA CDROM (1994)(Walnut Creek)[Feb 1994][W.O. 44790-1].iso / Aminet / dev / misc / toolbox.lha / Toolbox / Test / ALL / PL5.lalr.c < prev    next >
Encoding:
Text File  |  1993-03-14  |  6.7 KB  |  245 lines

  1. GLOBAL {#include "Tree.h"
  2.         typedef struct {tScanAttribute Scan;
  3.                         tTree v;             } tParsAttribute;}
  4.  
  5.  
  6. TOKEN
  7.  
  8. strings          = 1
  9. digis            = 2
  10.  
  11. "BEGIN"          = 3
  12. "END"            = 4
  13. "CONST"          = 5
  14. "VAR"            = 6
  15. "PROCEDURE"      = 7
  16. "TYPE"           = 8
  17. "ARRAY"          = 9
  18. "OF"             = 10
  19. "IF"             = 11
  20. "THEN"           = 12
  21. "ELSIF"          = 13
  22. "ELSE"           = 14
  23. "WHILE"          = 15
  24. "DO"             = 16
  25. "OR"             = 17
  26. "AND"            = 18
  27. "NOT"            = 19
  28. "ODD"            = 20
  29. "?"              = 21
  30. "!"              = 22
  31.  
  32. "="              = 23
  33. "#"              = 24
  34. "<"              = 25
  35. ">"              = 26
  36. "<="             = 27
  37. ">="             = 28
  38. "+"              = 29
  39. "-"              = 30
  40. "*"              = 31
  41. "/"              = 32
  42. ":="             = 33
  43.  
  44. ","              = 34
  45. ";"              = 35
  46. "."              = 36
  47. "("              = 37
  48. ")"              = 38
  49. "["              = 39
  50. "]"              = 40
  51. ":"              = 41
  52.  
  53. identy           = 42
  54.  
  55.  
  56. OPER
  57.  
  58. NONE "=" "<=" ">=" "<" ">" "#"
  59. LEFT "-" "+"
  60. LEFT "*" "/"
  61. LEFT "ODD"
  62.  
  63.  
  64. RULE
  65.  
  66. prog          : block "."
  67.                 {tTree t;
  68.                  t = mprogram($1.v); 
  69.                  CheckTree(t); 
  70.                  WriteTree(stdout,t);}.
  71.  
  72. block         : declaration_s
  73.                 "BEGIN"
  74.                    statements
  75.                 "END"
  76.                 {$$.v = mblock($1.v,$3.v);}.
  77.   
  78. declaration_s : declaration_s declaration
  79.                 {$$.v = mdecls1($2.v,$1.v);}.
  80. declaration_s :
  81.                 {$$.v = mdecls0();}.
  82.  
  83. declaration   : "CONST" const_s ";"
  84.                 {$$.v = mconstdefs($2.v);}.
  85. declaration   : "VAR" var_s ":" type ";"
  86.                 {$$.v = mvardefs($2.v,$4.v);}.
  87. declaration   : "TYPE" ident "=" type ";"
  88.                 {$$.v = mtypedefs($2.v,$4.v);}.
  89. declaration   : "PROCEDURE" ident parameter_s ";" block ";"
  90.                 {$$.v = mproceduredefs($2.v,$3.v,$5.v);}.
  91.  
  92. const_s       : const_s "," const
  93.                 {$$.v = mconst1($3.v,$1.v);}.
  94. const_s       : const
  95.                 {$$.v = mconst1($1.v,mconst0());}.
  96.  
  97. const         : ident "=" digi
  98.                 {$$.v = mConst($1.v,$3.v);}.
  99.  
  100. var_s         : var_s "," var
  101.                 {$$.v = mvar1($3.v,$1.v);}.
  102. var_s         : var
  103.                 {$$.v = mvar1($1.v,mvar0());}.
  104.  
  105. var           : ident
  106.                 {$$.v = mvar($1.v);}.
  107.  
  108. type          : ident
  109.                 {$$.v = mtyp1($1.v);}.
  110. type          : "ARRAY" digi "OF" type
  111.                 {$$.v = mtyp2($2.v,$4.v);}.
  112.  
  113. parameter_s   : 
  114.                 {$$.v = mpar0();}.
  115. parameter_s   : "(" parameterx ")"
  116.                 {$$.v = mpar1($2.v);}.
  117.  
  118. parameterx    : parameterx ";" parameter
  119.                 {$$.v = mparameter1($3.v,$1.v);}.
  120. parameterx    : parameter
  121.                 {$$.v = mparameter1($1.v,mparameter0());}.
  122.  
  123. parameter     : "VAR" para_s ":" type
  124.                 {$$.v = mparameter($2.v,$4.v,1);}.
  125. parameter     : para_s ":" type
  126.                 {$$.v = mparameter($1.v,$3.v,0);}.
  127.  
  128. para_s        : ident
  129.                 {$$.v = mident1($1.v,mident0());}.
  130. para_s        : para_s "," ident
  131.                 {$$.v = mident1($3.v,$1.v);}.
  132.  
  133. statements    : statement
  134.                 {$$.v = mstats0($1.v);}.
  135. statements    : statements ";" statement
  136.                 {$$.v = mstats1($3.v,$1.v);}.
  137.  
  138. statement     : 
  139.                 {$$.v = mstat0();}.
  140. statement     : variable ":=" formula
  141.                 {$$.v = mstat1($1.v,$3.v);}.
  142. statement     : ident
  143.                 {$$.v = mstat2($1.v,mact0());}.
  144. statement     : ident "(" actuals ")"
  145.                 {$$.v = mstat2($1.v,$2.v);}.
  146. statement     : "?" variable
  147.                 {$$.v = mstat3($2.v);}.
  148. statement     : "!" formula
  149.                 {$$.v = mout1($2.v);}.
  150. statement     : "!" string
  151.                 {$$.v = mout2($2.v);}.
  152.  
  153. statement     : "IF" formula "THEN" statements if_s "END" "IF"
  154.                 {$$.v = mstat5($2.v,$4.v,$5.v);}.
  155.  
  156. statement     : "WHILE" formula "DO" statements "END" "WHILE"
  157.                 {$$.v = mstat6($2.v,$4.v);}.
  158.  
  159. if_s          : 
  160.                 {$$.v = mels0();}.
  161. if_s          : if_s "ELSE" statements
  162.                 {$$.v = mels1($3.v);}.
  163. if_s          : if_s "ELSIF" formula "THEN" statements
  164.                 {$$.v = mels1(mstat5($3.v,$5.v,$1.v));}.
  165.  
  166. formula       : conjunction
  167.                 {$$.v = mforms0($1.v);}.
  168. formula       : formula "OR" conjunction
  169.                 {$$.v = mforms1($3.v,$1.v);}.
  170.  
  171. conjunction   : relation
  172.                 {$$.v = mconjs0($1.v);}.
  173. conjunction   : conjunction "AND" relation
  174.                 {$$.v = mconjs1($3.v,$1.v);}.
  175.  
  176. relation      : expression
  177.                 {$$.v = mrel0($1.v);}.
  178. relation      : expression "=" expression
  179.                 {$$.v = mrel1($1.v,0,$3.v);}.
  180. relation      : expression "#" expression
  181.                 {$$.v = mrel1($1.v,1,$3.v);}.
  182. relation      : expression "<" expression
  183.                 {$$.v = mrel1($1.v,2,$3.v);}.
  184. relation      : expression ">" expression
  185.                 {$$.v = mrel1($1.v,3,$3.v);}.
  186. relation      : expression "<=" expression
  187.                 {$$.v = mrel1($1.v,4,$3.v);}.
  188. relation      : expression ">=" expression
  189.                 {$$.v = mrel1($1.v,5,$3.v);}.
  190.  
  191. expression    : ["+"] exp_s term
  192.                 {$$.v = mexpression(0,$2.v,$3.v);}.
  193. expression    : "-" exp_s term
  194.                 {$$.v = mexpression(-1,$2.v,$3.v);}.
  195.  
  196. exp_s         : 
  197.                 {$$.v = mexps0();}.
  198. exp_s         : exp_s term "+"
  199.                 {$$.v = mexps1(mexp($2.v,0),$1.v);}.
  200. exp_s         : exp_s term "-"
  201.                 {$$.v = mexps1(mexp($2.v,-1),$1.v);}.
  202.  
  203. term          : term_s factor
  204.                 {$$.v = mterm($1.v,$2.v);}.
  205.  
  206. term_s        : 
  207.                 {$$.v = mtes0();}.
  208. term_s        : term_s factor "*"
  209.                 {$$.v = mtes1(mte($2.v,1),$1.v);}.
  210. term_s        : term_s factor "/"
  211.                 {$$.v = mtes1(mte($2.v,2),$1.v);}.
  212.  
  213. factor        : variable
  214.                 {$$.v = mfact1($1.v);}.
  215. factor        : digi
  216.                 {$$.v = mfact2($1.v);}.
  217. factor        : "ODD" factor
  218.                 {$$.v = mfact3(1,$2.v);}.
  219. factor        : "NOT" factor
  220.                 {$$.v = mfact3(2,$2.v);}.
  221. factor        : "(" formula ")"
  222.                 {$$.v = mfact4($2.v);}.
  223.  
  224. variable      : ident variable_s
  225.                 {$$.v = mvariable($1.v,$2.v);}.
  226.  
  227. variable_s    : 
  228.                 {$$.v = marr0();}.
  229. variable_s    : variable_s "[" expression "]"
  230.                 {$$.v = marr1($3.v,$1.v);}.
  231.  
  232. actuals       : formula
  233.                 {$$.v = mact1($1.v,mact0());}.
  234. actuals       : actuals "," formula
  235.                 {$$.v = mact1($3.v,$1.v);}.
  236.  
  237. ident         : identy
  238.                 {$$.v = mident($1.Scan.lexid);}.
  239.  
  240. string        : strings
  241.                 {$$.v = mstring($1.Scan.lexstring);}.
  242.  
  243. digi          : digis
  244.                 {$$.v = mnumber($1.Scan.lexstring);}.
  245.